/************************************************************************************************/
/*Lab 3: AssemblerClasses.cpp									*/
/*												*/
/*Description: This c file defines the commands for the "AssemblerData", the "AssemblyCommands",*/
/*	       and the "Comments" classes.							*/
/*												*/
/*Modification Log:										*/
/*												*/
/*		2012/02/28 - Updated this file to be compatable with the header file.		*/
/*			     (Samuel Thacker)							*/
/*		2012/02/15 - Created Append commands for "AssemblyCommands" for the "comments",	*/
/*			     "mc_data", and "errors" vectors. (Samuel Thacker)			*/
/*		2012/02/14 - Created Return commands for "AssemblyCommands".  Modified all 	*/
/*			     string return commands to return a string instead of a pointer.	*/
/*			     Created the Constructor, the Destructor, and the Return commands	*/
/*			     for the "Comments" class and the "Errors" class. (Samuel Thacker)	*/
/*		2012/02/13 - Created the Constructor, the Destructor, and the Return commands	*/
/*			     for the "AssemblerData" class.  Created the constructors and the	*/
/*			     destructor for the "AssemblyCommands" class. (Samuel Thacker)	*/ 
/*		2012/02/10 - Creation of this header file. (Samuel Thacker)			*/
/*												*/
/*               ----Please report any modifications made to this file please----               */
/************************************************************************************************/

#include <iostream>
#include <vector>
#include <string>
#include "AssemblerClasses.h"

using namespace std;

/*****************/
/* AssemblerData */
/*****************/

/* Constructor and Destructor */
AssemblerData::AssemblerData() //Constructor
	{
	data = new vector<AssemblyCommands>;
	directives = new vector<AssemblyCommands>;
	labels = new vector<General>;
	comments = new vector<General>;
	mc_data = new vector<unsigned int>;
	errors = new vector<string>;
	} //END AssemblerData()

AssemblerData::~AssemblerData() //Destructor
	{
	delete data;
	delete directives;
	delete labels;
	delete comments;
	delete mc_data;
	delete errors;
	} //END ~AssemblerData()

/* Return Commands */
vector<AssemblyCommands> * AssemblerData::ret_data() //Returns "data" (pointer).
	{
	return data;
	} //END ret_data()

vector<AssemblyCommands> * AssemblerData::ret_dir() //Returns "directives" (pointer).
	{
	return directives;
	} //END ret_dir()

vector<General> * AssemblerData::ret_lab() //Returns "comments" (pointer).
	{
	return labels;
	} //END ret_lab()

vector<General> * AssemblerData::ret_com() //Returns "comments" (pointer).
	{
	return comments;
	} //END ret_com()

vector<unsigned int> * AssemblerData::ret_mcData() //Returns "mc_data" (pointer).
	{
	return mc_data;
	} //END ret_mcData()

vector<string> * AssemblerData::ret_err() //Returns "errors" (pointer).
	{
	return errors;
	} //END ret_mcData()

/* Length Commands */
unsigned int AssemblerData::data_len() //Returns the number of elements in "data"
	{
	return (*data).size();
	} //END data_len()

unsigned int AssemblerData::dir_len() //Returns the number of elements in "directives"
	{
	return (*directives).size();
	} //END dir_len()

unsigned int AssemblerData::lab_len() //Returns the number of elements in "labels"
	{
	return (*labels).size();
	} //END lab_len()

unsigned int AssemblerData::com_len() //Returns the number of elements in "comments"
	{
	return (*comments).size();
	} //END com_len()

unsigned int AssemblerData::mcData_len() //Returns the number of elements in "mc_data"
	{
	return (*mc_data).size();
	} //END mcData_len()

unsigned int AssemblerData::err_len() //Returns the number of elements in "errors"
	{
	return (*errors).size();
	} //END err_len()

/* Append Commands */
void AssemblerData::data_append(vector<string> DATA,unsigned int LN,string FNAME) //Appends a list of tokens to "data"
	{
	(*data).push_back(AssemblyCommands(DATA,LN,FNAME));
	} //END data_append(vector<string> DATA,unsigned int LN,string FNAME)

void AssemblerData::dir_append(vector<string> DIR,unsigned int LN,string FNAME) //Appends a list of tokens to "directives"
	{
	(*directives).push_back(AssemblyCommands(DIR,LN,FNAME));
	} //END dir_append(vector<string> DIR,unsigned int LN,string FNAME)

void AssemblerData::lab_append(string LAB,unsigned int LN,string FNAME) //Appends a label to "labels"
	{
	(*labels).push_back(General(LAB,LN,FNAME));
	} //END lab_append(string COM,unsigned int LN,string FNAME)

void AssemblerData::com_append(string COM,unsigned int LN,string FNAME) //Appends a comment to "comments"
	{
	(*comments).push_back(General(COM,LN,FNAME));
	} //END com_append(string COM,unsigned int LN,string FNAME)

void AssemblerData::mcData_append(unsigned int MachineCode) //Appends machine code (integer) to "mc_data"
	{
	(*mc_data).push_back(MachineCode);
	} //END mcData_append(unsigned int MachineCode)

void AssemblerData::err_append(string ERR) //Appends a comment to "comments"
	{
	(*errors).push_back(ERR);
	} //END err_append(string ERR)

/* END AssemblerData */


/********************/
/* AssemblyCommands */
/********************/

/* Constructor and Destructor */

/* Constructor */
AssemblyCommands::AssemblyCommands(vector<string> CODE,unsigned int LN,string FNAME)
	{
	/* Creating Pointers */
	code = new vector<string>;
	fname = new string;

	/* Storing Strings */
	*code = CODE;
	*fname = FNAME;

	/* Line Number */
	ln = LN;
	
	} //END AssemblyCommands(string ODL, string REG_1, string REG_2, string REG_3, unsigned int LN)

/* Destructor */
AssemblyCommands::~AssemblyCommands()
	{
	delete code;
	delete fname;
	} //END ~AssemblyCommands()

/* Return Commands */
vector<string> * AssemblyCommands::ret_code() //returns "code" pointer
	{
	return code;
	} //END ret_code()

unsigned int AssemblyCommands::ret_ln() //returns "ln"
	{
	return ln;
	} //END ret_ln()

string AssemblyCommands::ret_fname() //returns what "fname" points to
	{
	return *fname;
	} //END ret_ln()

/* END AssemblyCommands */


/***********/
/* General */
/***********/

/* Constructor and Destructor */
General::General(string GEN, unsigned int LN,string FNAME) //Constructor
	{
	gen = new string; //allocates space for a "string class" and assigns a pointer to "com".
	fname = new string;

	*gen = GEN; //Copies string "COM" and assigns it to allocated "com"
	ln = LN; //Assigns the value of "LN" to "ln" (line number).
	*fname = FNAME;
	} //END Comments(string COM, unsigned int LN)

General::~General() //Destructor
	{
	delete gen;
	delete fname;
	} //END ~Comments()

/* Return Commands */
string General::ret_gen() //returns what "gen" points to
	{
	return *gen;
	} //END ret_gen()

unsigned int General::ret_ln() //returns "ln"
	{
	return ln;
	} //END ret_ln()

string General::ret_fname() //returns what "fname" points to
	{
	return *fname;
	} //END ret_fname()

/* END General */

/* EOF AssemblerClasses.cpp */
